package com.cqyc.shop.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cqyc.shop.comm.commException;
import com.cqyc.shop.domain.Orders;
import com.cqyc.shop.services.OrdersServices;

@WebServlet(urlPatterns="/orderdelete.do")
public class OrdersDeleteServlet extends  HttpServlet{
	private static final long serialVersionUID = -564891012132972245L;
	private Logger logger = LoggerFactory.getLogger(getClass());
	private OrdersServices ordersServices = new OrdersServices();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug("删除订单表演开始");
		try {
			//1:从前台获取参数
			String id = request.getParameter("id");
			logger.debug("{}",id);
			
			//2:数据转换
			Integer idd =Integer.valueOf(id);
			Orders orders = new Orders();
			orders.setId(idd);
			//3:数据校验
			if(id==null) {
				throw new commException("获取ID为空，无法取消订单");
			}
			
			
			//4:业务处理
			ordersServices.delete(idd);
			//5:跳转
		/*	response.sendRedirect(request.getContextPath()+"/orderslist.do");*/
			request.getRequestDispatcher("/orderslist.do").forward(request, response);
		} catch (Exception e) {
			logger.error("{}",e.getMessage());
			request.getRequestDispatcher("/userAccount/userOrder.jsp").forward(request, response);
		}
	}

}
